import { createRouter, createWebHashHistory } from 'vue-router'
import { routers } from './router.ts'
import storage from 'store'

const router = createRouter({
	history: createWebHashHistory(),
	routes: routers
})
router.beforeEach((_to:any, _from:any, next:any) => {
	let token = storage.get("token")
	if (!token && _to.path !== '/login'){
		next({path: "/login"})
	} else if (token && _to.path === '/login') {
		next({path: "/"})
	} else  {
		next()
	}
})
router.afterEach(() => {
})
export default router